using System;
using System.Collections.Generic;
using System.Linq;
using ZQNB.BaseLib.Core.Models;

namespace ZQNB.BaseLib.Core.Services
{
    public class OpServiceMemory : IOpService
    {
        
        private static IList<Op> _ops = new List<Op>();

        public void Init(IList<Op> ops, bool replaceExist = false)
        {
            _ops = ops;
        }

        public void Validate(IList<Op> models)
        {
        }

        public IList<Op> GetAll(string category, string module)
        {
            var query = _ops.AsQueryable();
            if (category != null)
            {
                query = query.Where(x => category.Equals(x.Category, StringComparison.OrdinalIgnoreCase));
                //query = query.Where(x => x.Category == category);
            }
            if (module != null)
            {
                query = query.Where(x => module.Equals(x.Module, StringComparison.OrdinalIgnoreCase));
                //query = query.Where(x => x.Module == module);
            }
            return query.OrderBy(x => x.SortNum)
                .ThenBy(x => x.Href)
                .ToList();
        }
        
    }
}